package com.clickpaas.materialsprocurement.service.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.ShareWarehouseDTOResponse;
import com.clickpaas.materialsprocurement.dao.SharedInventDao;
import com.clickpaas.materialsprocurement.entity.SharedInventEntity;
import com.clickpaas.materialsprocurement.service.SharedInventService;
import com.clickpaas.materialsprocurement.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class SharedInventServiceImpl implements SharedInventService {
    @Resource
    private SharedInventDao sharedInventDao;
    /**
     * 获取请购单物料数据
     *
     * @param sharedInventEntity
     * @return
     */
    @Override
    public List<ShareWarehouseDTOResponse> getSharedInventInfo(SharedInventEntity sharedInventEntity) {

        List<ShareWarehouseDTOResponse> reDataList;
        try {
            /**
             * 入参为空,不查询
             */
            if (null == sharedInventEntity || DataInfoUtil.isAllFieldNull(sharedInventEntity)){
                return null;
            }else {
                reDataList = sharedInventDao.getShareInventByCondtion(sharedInventEntity);
            }
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",sharedInventEntity,e);
            return null;
        }
        if (null != reDataList && reDataList.size()>0){
            return reDataList;
        }
        return null;
    }

    @Override
    public List<SharedInventEntity> SharedInventDataConver(List<ShareWarehouseDTOResponse> dataLists){
        return DataInfoUtil.castListCopy(dataLists,ShareWarehouseDTOResponse.class,SharedInventEntity.class);
    }

    /**
     * 共享库存数据入库
     *
     * @param sharedInventEntity
     * @return
     */
    @Override
    public Boolean insertSharedInventInfo(SharedInventEntity sharedInventEntity) {
        if (null == sharedInventEntity)return false;
        return sharedInventDao.insertShareInvent(sharedInventEntity);
    }
}
